package upload

import (
	"time"
	"gorm.io/gorm"
)

// File 文件模型
type File struct {
	ID           uint           `json:"id" gorm:"primaryKey;autoIncrement" comment:"文件ID"`
	OriginalName string         `json:"original_name" gorm:"size:255;not null" comment:"原始文件名"`
	FileName     string         `json:"file_name" gorm:"size:255;not null" comment:"存储文件名"`
	FilePath     string         `json:"file_path" gorm:"size:500;not null" comment:"文件路径"`
	FileURL      string         `json:"file_url" gorm:"size:500;not null" comment:"文件访问URL"`
	FileSize     int64          `json:"file_size" gorm:"not null" comment:"文件大小(字节)"`
	FileType     string         `json:"file_type" gorm:"size:100;not null" comment:"文件类型"`
	MimeType     string         `json:"mime_type" gorm:"size:100;not null" comment:"MIME类型"`
	Extension    string         `json:"extension" gorm:"size:20;not null" comment:"文件扩展名"`
	Hash         string         `json:"hash" gorm:"size:64;unique;not null" comment:"文件哈希值"`
	StorageType  string         `json:"storage_type" gorm:"size:20;default:local" comment:"存储类型(local/oss/cos等)"`
	UserID       *uint          `json:"user_id" gorm:"index" comment:"上传用户ID"`
	Status       int            `json:"status" gorm:"default:1;not null" comment:"状态(1:正常 0:删除)"`
	CreatedAt    time.Time      `json:"created_at" gorm:"autoCreateTime" comment:"创建时间"`
	UpdatedAt    time.Time      `json:"updated_at" gorm:"autoUpdateTime" comment:"更新时间"`
	DeletedAt    gorm.DeletedAt `json:"deleted_at" gorm:"index" comment:"删除时间"`
}

// TableName 设置表名
func (File) TableName() string {
	return "files"
}

// UploadRequest 上传请求
type UploadRequest struct {
	Type        string `json:"type" form:"type" comment:"上传类型(image/document/video等)"`
	Category    string `json:"category" form:"category" comment:"分类"`
	Description string `json:"description" form:"description" comment:"文件描述"`
}

// UploadResponse 上传响应
type UploadResponse struct {
	ID           uint   `json:"id" comment:"文件ID"`
	OriginalName string `json:"original_name" comment:"原始文件名"`
	FileName     string `json:"file_name" comment:"存储文件名"`
	FileURL      string `json:"file_url" comment:"文件访问URL"`
	FileSize     int64  `json:"file_size" comment:"文件大小"`
	FileType     string `json:"file_type" comment:"文件类型"`
	MimeType     string `json:"mime_type" comment:"MIME类型"`
	Extension    string `json:"extension" comment:"文件扩展名"`
	Hash         string `json:"hash" comment:"文件哈希值"`
}

// DeleteRequest 删除文件请求
type DeleteRequest struct {
	FileID   *uint   `json:"file_id" comment:"文件ID"`
	FileName *string `json:"file_name" comment:"文件名"`
	FileURL  *string `json:"file_url" comment:"文件URL"`
}

// QueryRequest 查询文件请求
type QueryRequest struct {
	Page        int    `json:"page" form:"page" binding:"min=1"`
	PageSize    int    `json:"page_size" form:"page_size" binding:"min=1,max=100"`
	Keyword     string `json:"keyword" form:"keyword"`
	FileType    string `json:"file_type" form:"file_type"`
	Extension   string `json:"extension" form:"extension"`
	StorageType string `json:"storage_type" form:"storage_type"`
	UserID      *uint  `json:"user_id" form:"user_id"`
	Status      *int   `json:"status" form:"status"`
}

// FileInfo 文件信息
type FileInfo struct {
	ID           uint      `json:"id"`
	OriginalName string    `json:"original_name"`
	FileName     string    `json:"file_name"`
	FilePath     string    `json:"file_path"`
	FileURL      string    `json:"file_url"`
	FileSize     int64     `json:"file_size"`
	FileType     string    `json:"file_type"`
	MimeType     string    `json:"mime_type"`
	Extension    string    `json:"extension"`
	Hash         string    `json:"hash"`
	StorageType  string    `json:"storage_type"`
	UserID       *uint     `json:"user_id"`
	Status       int       `json:"status"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

// BatchDeleteRequest 批量删除请求
type BatchDeleteRequest struct {
	FileIDs []uint `json:"file_ids" binding:"required" comment:"文件ID列表"`
}

// UploadConfig 上传配置
type UploadConfig struct {
	MaxFileSize   int64    `json:"max_file_size" comment:"最大文件大小(字节)"`
	AllowedTypes  []string `json:"allowed_types" comment:"允许的文件类型"`
	AllowedExts   []string `json:"allowed_exts" comment:"允许的文件扩展名"`
	StorageDriver string   `json:"storage_driver" comment:"存储驱动"`
	UploadPath    string   `json:"upload_path" comment:"上传路径"`
}
